#!/bin/bash
# 编译Solidity合约脚本

echo "Compiling ERC20Token.sol..."

# 检查solc是否安装
if ! command -v solc &> /dev/null
then
    echo "Error: solc (Solidity compiler) is not installed."
    echo "Please install it using: npm install -g solc"
    exit 1
fi

# 创建输出目录
mkdir -p build/contracts
mkdir -p src/main/resources/contracts

# 编译合约
solc --bin --abi src/main/resources/contracts/ERC20Token.sol -o build/contracts/

# 检查编译是否成功
if [ -f "build/contracts/ERC20Token.bin" ]; then
    echo "Contract compiled successfully!"
    echo "Copying bytecode to resources..."
    cp build/contracts/ERC20Token.bin src/main/resources/contracts/
    echo "Done! Contract bytecode is now available at src/main/resources/contracts/ERC20Token.bin"
else
    echo "Error: Compilation failed. Please check the Solidity contract."
    exit 1
fi

